from PySide6.QtWidgets import QDialog, QFileDialog, QPushButton, QVBoxLayout, QHBoxLayout, QFrame

from gui.base import WindowBase


class FileMenuDialog(WindowBase):
    """
    本类实现文件对话框，保存，等多个静态对话框
    """
    def __init__(self):
        super().__init__()
        self.filefilter = None # 文件过滤器
        self.config = self.baseconfig

    def file_dialog(self):
        filepath,self.filefilter = QFileDialog().\
            getOpenFileNames(self,
                             caption= self.config['open_file']['caption'],
                             dir= self.config['open_file']['url'],
                             filter= self.config['open_file']['filter']
                             )
        return filepath

    def save_file_dialog(self):
        filteruse = self.filefilter or self.config['save_file']['filter']
        return QFileDialog().getSaveFileName\
            (self,
             caption= self.config['save_file']['caption'],
             dir= self.config['save_file']['url'],
             filter= filteruse
             )

    def saveas_file_dialog(self):
        filteruse = self.filefilter or self.config['saveas_file']['filter']
        return QFileDialog().getSaveFileUrl\
            (self,
             caption= self.config['saveas_file']['caption'],
             dir= self.config['saveas_file']['url'],
             filter= filteruse
             )

    def setting_dialog_box(self):
        return

class SetWindowBase(WindowBase):
    """
    本类实现设置对话框基础模块实现
    """
    def __init__(self, logic=None):
        super().__init__()
        self.dialog = QDialog()
        self.logic = logic
        self.button()
        self.setLayout(self._Setup_())

    def confirm(self):
        btn = QPushButton('确认')
        btn.clicked.connect(self.logic)
        return btn

    def cancel(self):
        btn = QPushButton('取消')
        btn.clicked.connect(self.logic)
        return btn

    def apply(self):
        btn = QPushButton('应用')
        btn.clicked.connect(self.logic)
        return btn

    def button(self):
        frame = QFrame()
        hlayout = QHBoxLayout(frame)
        hlayout.addWidget(self.confirm())
        hlayout.addWidget(self.cancel())
        hlayout.addWidget(self.apply())
        return frame

    def _Setup_(self):
        vlayout = QVBoxLayout(self.dialog)
        vlayout.addWidget(self.button(), self.Qt.AlignmentFlag.AlignBottom)
        vlayout.addStretch(1)
        return vlayout

class SetWindow(SetWindowBase):
    """
    本类实现设置对话框的细节组件，交互，逻辑绑定，每页页面，页面切换的具体实现
    """
    def __init__(self, logic = None):
        super().__init__(logic)

    def open_win(self):
        self._config()
        self.combinction_set_window()

        self.dialog.exec()

    def _config(self):
        pass

    def combinction_set_window(self):
        self._Setup_().addWidget(self.page_1())

    def page_1(self):
        frame = QFrame()
        return frame


if __name__ == '__main__':
    pass